Programming and management of experiments in oTree

Module 4: Online Deployment

Authors
Affiliations

Matteo Ploner

Università di Trento

Luca Congiu

Università degli Studi di Roma “Tor Vergata”

Published

July 2025

oTree: Online Deployment

From local to online

  • When you test your software you deploy it locally with command
otree devserver
  • To deploy it online we need to take the app to an oline server
  • We can use the oTree hub or a cloud service
    • A possible cloud solution is render.com
      • Free with limitations
      • Works with Github
    • In the past we used Heroku but it is not free anymore

Github

Step 1: create a Github account

  • Go to github.com and create an account (if you do not have one)
  • Create a new repository

  • Name it something like otree-experiments
    • Name is free

Render.com

Step 2: create a render.com account

  • Go to render.com and create an account (if you do not have one)
  • I signed in with my existing Github account

  • Choose a free plan
    • Individual is free but limited

Step 3a: create a render.com web service

  • Create a new web service

  • Set properties like in the figure

Step 3b: create a render.com web service

  • Setup environment variables

  • Set properties like in the figure
    • OTREE_ADMIN_PASSWORD: [here your password]
    • OTREE_AUTH_LEVEL: STUDY
    • OTREE_PRODUCTION: 1
    • PYTHON_VERSION: 3.9.13

Github → Render.com

Step 4: upload your files to Github

  • Upload your oTree repository to Github
    • App + settings.py +requirements.txt

r
  • Commit your changes
    • The process is smoother if you clone the repository on your computer
      • Better to use Gitub Desktop to manage the commits

Step 5: test your app

  • If you go to the webpage

  • You should see the app running

  • Enter your admin password

Data collection

Your data in good shape

  • Data Wrangling is “the art of getting your data into R in a useful form for visualization and modeling(Wickham and Grolemund 2016)

  • We rely on the tidyverse library

    • The tidyverse is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures.
library(tidyverse)

The Workflow

  • Wickham and Grolemund (2016) present a description of the workflow in data management

Tidy data

  • See Wickham (2014) for a description of good practices in organizing your data 1.

  • 3 rules to have tidy data

    • Each variable forms a column.
    • Each observation forms a row.
    • Each type of observational unit forms a table.


Source: Wickham and Grolemund (2016)

  • Data that are not tidy are untidy!

Export data from oTree

  • Download your data in .csv format
    • Open format

Import data

  • Import your data into your favorite statistical software
    • R, Stata, SPSS, Excel, etc.
  • Here the reference is to R
library(tidyverse)
data <- read_csv("all_apps_wide-2024-02-15.csv")
  • Inspect your data
view(data)
  • Number of participants: 3

  • Number of sessions: 1

Data cleaning

  • Select the relevant columns
d.sel <- data |> 
                select(
                participant.code,
                session.code,
                paste("PGG.",1:3,".player.choice",sep=""),
                paste("PGG.",1:3,".player.payoff",sep=""),
                paste("PGG.",1:3,".group.total_choices",sep=""))
participant.code session.code PGG.1.player.choice PGG.2.player.choice PGG.3.player.choice PGG.1.player.payoff PGG.2.player.payoff PGG.3.player.payoff PGG.1.group.total_choices PGG.2.group.total_choices PGG.3.group.total_choices
s2b3bmdu bsy4ctig 55 5 66 106 138 118 92 65 126
mp9d7lsf bsy4ctig 4 5 5 157 138 179 92 65 126
pmwln29a bsy4ctig 33 55 55 128 88 129 92 65 126

Description

Table 1: Descriptive statistics

d.sel  |> 
select( paste("PGG.", 1:3, ".player.choice", sep = "")) |> 
summary() 
PGG.1.player.choice PGG.2.player.choice PGG.3.player.choice
Min. : 4.00 Min. : 5.00 Min. : 5.0
1st Qu.:18.50 1st Qu.: 5.00 1st Qu.:30.0
Median :33.00 Median : 5.00 Median :55.0
Mean :30.67 Mean :21.67 Mean :42.0
3rd Qu.:44.00 3rd Qu.:30.00 3rd Qu.:60.5
Max. :55.00 Max. :55.00 Max. :66.0

Graphs

d.sel |>
    select(participant.code, paste("PGG.", 1:3, ".player.choice", sep = "")) |>
    pivot_longer(cols = 2:4) |>
    mutate(Round = as.numeric(str_extract(name, "\\d+"))) -> d.g

ggplot(d.g, aes(x = Round, y = value, color = participant.code)) +
    geom_line(linewidth = 1) +
    geom_point(size = 4) +
    geom_line(data = d.g |> group_by(Round) |> summarise(value = mean(value)) |> ungroup(), aes(x = Round, y = value, color = "Mean"), linetype = "dashed", color = "Black", linewidth = 2) +
    geom_point(data = d.g |> group_by(Round) |> summarise(value = mean(value)) |> ungroup(), aes(x = Round, y = value, color = "Mean"), size = 4, color="Black") +
    geom_line(stat = "summary", fun = "mean", linetype = "dashed") +
    scale_x_continuous(breaks = 1:3) +
    scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, 10)) +
    theme_minimal()

References

References

Wickham, Hadley. 2014. “Tidy Data.” The Journal of Statistical Software 59. http://www.jstatsoft.org/v59/i10/.
Wickham, Hadley, and Garrett Grolemund. 2016. R for Data Science: Import, Tidy, Transform, Visualize, and Model Data. " O’Reilly Media, Inc.".

Footnotes

  1. A condensed online version available here.↩︎